const { Builder } = require('selenium-webdriver')
const getIOSInfo = require('./ios/getInfo')
const getAndroidInfo = require('./android/getInfo')
const getDriver = require('./getDriver')

module.exports = function lanuchBrowser (num, taskDispatcher, kind) {
  const tasks = []
  for (let i = 0; i < num; i += 1) {
    let driver = getDriver()
    let idleIndex = taskDispatcher.dispatch()
    if (idleIndex === -1) break
    let p
    if (kind === 'ios') {
      p = getIOSInfo(driver, idleIndex, taskDispatcher)
    } else {
      p = getAndroidInfo(driver, idleIndex, taskDispatcher)
    }
    tasks.push(p)
  }
  return Promise.all(tasks)
}